//
//  LinkViewController.m
//  HGMMT
//
//  Created by eport_user1 on 2018/4/8.
//  Copyright © 2018年 eport_user1. All rights reserved.
//

#import "LinkViewController.h"
#import "QRcodeViewController.h"
#import "IDELinkViewController.h"
#import "GetListViewController.h"

static NSString *iden = @"cell_iden";

@interface LinkViewController ()<UITableViewDelegate,UITableViewDataSource>

@property(nonatomic,strong)UITableView *tableview;
@property(nonatomic,strong)NSMutableArray *mutaArray;

@end

@implementation LinkViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    [self _loadData];
    [self _initNav];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


#pragma mark - 导航设置
-(void)_initNav{
    
    self.title = @"连接开发套件";
    self.tableview.backgroundColor = [UIColor whiteColor];
    UIBarButtonItem *item = [[UIBarButtonItem alloc]initWithTitle:@"返回" style:(UIBarButtonItemStylePlain) target:self action:nil];
    self.navigationItem.backBarButtonItem = item;
    
}

-(void)_loadData{
    
    NSArray *array = @[@"二维码扫描连接",@"输入IDE识别码连接",@"获取IDE识别码列表连接"];
    self.mutaArray = [NSMutableArray arrayWithArray:array];
    
    
}

#pragma mark -初始化视图

-(UITableView *)tableview{
    
    if (_tableview == nil) {
        
        _tableview = [[UITableView alloc]initWithFrame:[UIScreen mainScreen].bounds style:(UITableViewStylePlain)];
        _tableview.delegate = self;
        _tableview.dataSource = self;
        [self.view addSubview:_tableview];
        [Tool setExtraCellLineHidden:_tableview];
        
    }
    
    return _tableview;
    
}




#pragma mark - 代理协议
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return self.mutaArray.count;
    
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:iden];
    
    if (cell == nil) {
        
        cell = [[UITableViewCell alloc]initWithStyle:(UITableViewCellStyleDefault) reuseIdentifier:iden];
        
        
    }
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    
    NSString *text = self.mutaArray[indexPath.row];
    cell.textLabel.text = text;
    cell.textLabel.font = [UIFont systemFontOfSize:18];
    return cell;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return 1;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return 60;
    
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
 
    return 40;
}


-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    
    UIView *view1 = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, 40)];
    view1.backgroundColor = [UIColor lightGrayColor];
    UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(15, (40 - 20)/2.0,(kScreenWidth - 15* 2)/2.0, 20)];
    label.textColor = [UIColor blackColor];
    label.font = [UIFont systemFontOfSize:15];
    label.text = @"请选择连接开发套件方式";
    [view1 addSubview:label];
    return view1;
    
    
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    if (indexPath.row == 0) {
    
        QRcodeViewController *qr = [[QRcodeViewController alloc]init];
        
        [self.navigationController pushViewController:qr animated:YES];
        
    }else if (indexPath.row == 1){
        
        IDELinkViewController *link = [[IDELinkViewController alloc]init];
        [self.navigationController pushViewController:link animated:YES];
        link.block = ^(NSString *string) {
            
            NSLog(@"%@",string);
            
        };
        
        
    }else if (indexPath.row == 2){
        
        GetListViewController *list = [[GetListViewController alloc]init];
        [self.navigationController pushViewController:list animated:YES];
        
    }
    
}

@end
